home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c,comp.unix.programmer
- Subject: Re: Running out of memory with mmap
- Followup-To: comp.unix.programmer
- Date: 6 Mar 1996 00:27:38 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4hji9qINNopi@keats.ugrad.cs.ubc.ca>
- References: <4hiq9o$h18@news.acns.nwu.edu>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
- Keywords: mmap
-
- In article <4hiq9o$h18@news.acns.nwu.edu>,
- George Johnson <johnson@immuno.bme.nwu.edu> wrote:
- >
- >Hi folks--
- >
- >
- >I have this procedure which is called a few thousand times, each time
- >with different requests for information from different large files.
- >Within this procedure is :
- >
- > ....
- >
- > pa = mmap(0,fsiz,PROT_READ,MAP_PRIVATE,fpB,0);
- >
- > madvise(pa,fsiz,MADV_RANDOM);
- >
- > if ( pa == (caddr_t) -1) {
- > perror("mmap failed");
- > exit(1);
- > }
- >
- > .... go to the specified offset in the file, grab the info
- >
- > .... leave procedure
- >
- >The size of the file(s) fpB are around 20 MB a piece. What happens
- >is that after 100 or so calls, the program exits saying it has run
- >out of memory.
- >
- >My question is where did the memory go? I don't understand what is
- >going on. I free all malloc'ed stuff, there is little else going on
- >in the program other than opening these big files, reading through
- >them and grabbing out little pieces of information.
- >
- >My assumption (hehehe) from reading the manual page for mmap and
- >munmap is that when mmap is called, it unmaps implicitly anybody
- >occupying space 0 to fsiz, so no munmap is needed to free up (?)
-
- You have misread the documentation. The address zero just tells mmap() to find
- you a suitable region in your virtual address space to map an object. A mmap
- will never overlap with existing memory maps.
-
- >I'm not sure what I'm forgetting to do.
-
- Use munmap(). Otherwise, you are spamming your virtual address space!
-
- >Any suggestions would be very helpful.
-
- How about this: take it to comp.unix.programmer where they would _love_ to
- discuss mmap() with you for the next three weeks! I would too, just not here.
- --
-
-